package com.wms.ymcc;

import com.wms.ymcc.domain.Login;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : 阿盛哟
 * @description :
 * @createDate : 2025/6/4 17:50
 */

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MediaApp.class)
public class Test1 {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;


    // 单项消息
    @Test
    public void test1() {
        // 发了就不管了。
        rocketMQTemplate.sendOneWay("topic-test:sms",  "hello world");
        System.out.println("发送成功");
    }


    /**
     * 同步消息
     * @throws IOException
     */
    @Test
    public void test2() throws IOException {

        // message:  topic    sms:  tags

        Login login = new Login();
        SendResult result = rocketMQTemplate.syncSend("message:sms",
                MessageBuilder.withPayload(JSONObject.toJSONString(login)).build());
        //打印结果
        System.out.println(result);
    }

    @Test
    public void test3() {
        rocketMQTemplate.asyncSend("message3:sms3", "我是短信消息",
                new SendCallback() {
                    @Override
                    public void onSuccess(SendResult sendResult) {

                        // 发送成功的回调函数
                        System.out.println(sendResult);
                    }

                    @Override
                    public void onException(Throwable e) {
                        // 异常了。没发送成功
                        e.printStackTrace();
                    }
                });
      /*  try {
            Thread.sleep(1000000000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }*/

    }









//     @Test
//    public void testVideoBuilder() {
//        ProcessBuilder processBuilder = new ProcessBuilder();
//        List<String> commond = new ArrayList<>();
//        commond.add("D:\\software\\install\\ffmpe\\bin\\ffmpeg");
//        commond.add("-i");
//        commond.add("D:\\d\\0\\d0fce1be39a4eaf50eaf6ea30f6ed3d6\\d0fce1be39a4eaf50eaf6ea30f6ed3d6.mp4");
//        commond.add("-hls_time");
//        commond.add("10");
//        commond.add("-hls_list_size");
//        commond.add("0");
//        commond.add("-hls_segment_filename");
//        commond.add("D:\\d\\0\\d0fce1be39a4eaf50eaf6ea30f6ed3d6\\aa\\habor%05d.ts");
//        commond.add("D:\\d\\0\\d0fce1be39a4eaf50eaf6ea30f6ed3d6\\aa\\habor.m3u8");
//        processBuilder.command(commond);
//        //将标准输入流和错误输入流合并，通过标准输入流读取信息
//        processBuilder.redirectErrorStream(true);
//        try {
//            //启动进程
//            Process start = processBuilder.start();
//            //获取输入流
//            InputStream inputStream = start.getInputStream();
//            //转成字符输入流
//            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "gbk");
//            int len = -1;
//            char[] c = new char[1024];
//            StringBuffer outputString = new StringBuffer();
//            //读取进程输入流中的内容
//            while ((len = inputStreamReader.read(c)) != -1) {
//                String s = new String(c, 0, len);
//                outputString.append(s);
//                System.out.print(s);
//            }
//            inputStream.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }


}